<script>
    $(document).ready(function($) {

        "<?php $i = '_1';?>"
        "<?php for($n=1; $n<=5; $n++) { ?>"
            if($('#gift<?php echo $i?> option:selected').val() == 'item')
            {
                $('#item<?php echo $i?>').attr('disabled', false);
            }
            else
            {
                $('#item<?php echo $i?>').attr('disabled', true);
            }

            $('#gift<?php echo $i?>').change(function()
            {
                if($('#gift<?php echo $i?> option:selected').val() == 'item')
                {
                    $('#item<?php echo $i?>').attr('disabled', false);
                }
                else
                {
                    $('#item<?php echo $i?>').attr('disabled', true);
                }
            });
        "<?php $i++;?>"
        "<?php }?>"
        var startDateTextBox = $('#event_start_date');
        var endDateTextBox = $('#event_end_date');

        startDateTextBox.datetimepicker({
            dateFormat: 'yy-mm-dd',
            timeFormat: 'HH:mm',
            stepHour: 1,
            stepMinute: 1,
            onClose: function(dateText, inst) {
                if (endDateTextBox.val() != '') {
                    var testStartDate = startDateTextBox.datetimepicker('getDate');
                    var testEndDate = endDateTextBox.datetimepicker('getDate');
                    if (testStartDate > testEndDate)
                        endDateTextBox.datetimepicker('setDate', testStartDate);
                }
                else {
                    endDateTextBox.val(dateText);
                }
            },
            onSelect: function (selectedDateTime){
                endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );
            }
        });
        endDateTextBox.datetimepicker({
            dateFormat: 'yy-mm-dd',
            timeFormat: 'HH:mm',
            stepHour: 1,
            stepMinute: 1,
            onClose: function(dateText, inst) {
                if (startDateTextBox.val() != '') {
                    var testStartDate = startDateTextBox.datetimepicker('getDate');
                    var testEndDate = endDateTextBox.datetimepicker('getDate');
                    if (testStartDate > testEndDate)
                        startDateTextBox.datetimepicker('setDate', testEndDate);
                }
                else {
                    startDateTextBox.val(dateText);
                }
            },
            onSelect: function (selectedDateTime){
                startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );
            }
        });

    });
</script>

<div class="tales_stats_menu">
    <ui>
        <li class="tales_of_deonia"><?php echo __(LANG_TALES_OF_DEONIA)?></li>
    </ui>
</div>

<!-- Etc 메뉴 -->
<div class="tales_stats_menu">
    <ul>
        <li class="actions">
            <?php echo $this->Html->link(__('Event'), array('action' => 'event_setting'));?>
        </li>
        <li class="actions">
            <?php echo $this->Html->link(__('Server'), array('action' => 'system_setting'));?>
        </li>
    </ul>
</div>

<div class="event_main">
    <div class="event_main_one">
        <div>
            <?php echo $this->Form->create('event_setting', array('onsubmit' => 'return confirm('.'"'.__('Read??').'");'));?>
            <?php echo $this->Form->hidden('event_num', array(
                'label' => false,
                'value' => $event_table['tbl_event_table']['event_num']
            ));?>
        </div>
        <div class="div_title"><?php echo __('Event Setting')?></div>

        <table border="0">
            <tr>
                <th class="user" style="width: 100px"><?php echo __('Event Start')?></th>
                <td class="background_white" colspan="3" style="padding-right: 19px">
                    <?php echo $this->Form->input('start_date', array(
                        'label' => false,
                        'type' => 'text',
                        'id' => 'event_start_date',
                        'value' => $event_table['tbl_event_table']['login_evt_start_date']
                    ));?>
                </td>
            </tr>
            <tr>
                <th class="user"><?php echo __('Event End')?></th>
                <td class="background_white" colspan="3" style="padding-right: 19px">
                    <?php echo $this->Form->input('end_date', array(
                        'label' => false,
                        'type' => 'text',
                        'id' => 'event_end_date',
                        'value' => $event_table['tbl_event_table']['login_evt_end_date']
                    ));?>
                </td>
            </tr>

            <tr>
                <th class="user" style="width: 90px"><?php echo __('Message')?></th>
                <td class="background_white" colspan="3" style="padding-right: 19px">
                    <?php echo $this->Form->input('message', array(
                        'label' => false,
                        'type' => 'text',
                        'value' => $event_table['tbl_event_table']['login_evt_msg']
                    ));?>
                </td>
            </tr>

            <?php
            $i = '_1';
            for($j = 1; $j<=5; ++$j) {
                if(!empty($login_reward[$j-1]['reward'])) {?>
                    <tr>
                        <th class="user"><?php echo __('Reward ' . $j)?></th>
                        <td class="background_white" style="padding-right: 19px;padding-top: 10px">
                            <?php echo $this->Form->input('gift'.$i, array(
                                'label' => false,
                                'type' => 'select',
                                'id' => 'gift'.$i,
                                'options' => giftOption(),
                                'value' => $login_reward[$j-1]['reward']
                            ));?>
                        </td>
                        <td class="background_white" style="padding-right: 19px">
                            <?php echo $this->Form->input('ea'.$i, array(
                                'label' => false,
                                'type' => 'text',
                                'id' => 'ea'.$i,
                                'value' =>
                                    empty($login_reward[$j-1]['count']) ?
                                        $login_reward[$j-1][$login_reward[$j-1]['reward']] : $login_reward[$j-1]['count']
                            ));?>
                        </td>
                        <?php if($login_reward[$j-1]['reward'] == 'item') {?>
                            <td class="background_white" style="padding-right: 19px;padding-top: 10px">
                                <?php echo $this->Form->input('item'.$i, array(
                                    'label' => false,
                                    'type' => 'select',
                                    'id' => 'item'.$i,
                                    'options' => $gift_item_option,
                                    'value' => $login_reward[$j-1][$login_reward[$j-1]['reward']]
                                ));?>
                            </td>
                        <?php } else {?>
                            <td class="background_white" style="padding-right: 19px;padding-top: 10px">
                                <?php echo $this->Form->input('item'.$i, array(
                                    'label' => false,
                                    'type' => 'select',
                                    'id' => 'item'.$i,
                                    'options' => $gift_item_option,
                                ));?>
                            </td>
                        <?php }?>
                    </tr>
                <?php } else {?>
                    <tr>
                        <th class="user"><?php echo __('Reward ' . $j)?></th>
                        <td class="background_white" style="padding-right: 19px;padding-top: 10px">
                            <?php echo $this->Form->input('gift'.$i, array(
                                'label' => false,
                                'type' => 'select',
                                'id' => 'gift'.$i,
                                'options' => giftOption(),
                                'value' => 'empty'
                            ));?>
                        </td>
                        <td class="background_white" style="padding-right: 19px">
                            <?php echo $this->Form->input('ea'.$i, array(
                                'label' => false,
                                'type' => 'text',
                                'id' => 'ea'.$i
                            ));?>
                        </td>
                        <td class="background_white" style="padding-right: 19px;padding-top: 10px">
                            <?php echo $this->Form->input('item'.$i, array(
                                'label' => false,
                                'type' => 'select',
                                'id' => 'item'.$i,
                                'options' => $gift_item_option
                            ));?>
                        </td>
                    </tr>
                <?php }?>
                <?php ++$i?>
            <?php }?>
        </table>
        <table>
            <tr>
                <td class="message_box no_border">
                    <?php if(!empty($err_msg)) {?>
                        <p class="error_message"><?php echo $err_msg?></p>
                    <?php } else  if(!empty($sus_msg)){?>
                        <p class="success_message"><?php echo $sus_msg?></p>
                    <?php }?>
                </td>
                <td class="no_border" style="text-align: right">
                    <?php echo $this->Form->end(__(LANG_SAVE));?>
                </td>
            </tr>
        </table>
    </div>
</div>